package com.qf.set.service.impl;


import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import com.qf.common.core.page.TableDataInfo;
import com.qf.set.domain.TmsEmployee;
import com.qf.set.mapper.TmsEmployeeMapper;
import com.qf.set.service.ITmsEmployeeService;
import com.qf.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;


import static com.qf.common.utils.PageUtils.startPage;

@Service
public class TmsEmployeeServiceImpl implements ITmsEmployeeService {

    @Autowired
    private TmsEmployeeMapper employeeMapper;

    @Override
    public List<TmsEmployee> selectEmployeePage(TmsEmployee employee) {
        startPage();
        List<TmsEmployee> list = employeeMapper.selectEmployeeList(employee);
        return list;
    }

    @Override
    public List<TmsEmployee> selectEmployeeList(TmsEmployee employee) {
        return employeeMapper.selectEmployeeList(employee);
    }

    @Override
    public TmsEmployee selectEmployeeById(String employeeId) {
        return employeeMapper.selectEmployeeById(employeeId);
    }

    @Override
    public int insertEmployee(TmsEmployee employee) {
        // 设置当前登录用户为创建人
        employee.setCreator(SecurityUtils.getUsername());
        return employeeMapper.insertEmployee(employee);
    }

    @Override
    public int updateEmployee(TmsEmployee employee) {
        return employeeMapper.updateEmployee(employee);
    }

    @Override
    public int deleteEmployeeById(String employeeId) {
        return employeeMapper.deleteEmployeeById(employeeId);
    }

    @Override
    public int deleteEmployeeByIds(String[] employeeIds) {
        return employeeMapper.deleteEmployeeByIds(employeeIds);
    }

    @Override
    @Transactional
    public int importEmployees(List<TmsEmployee> employees) {
        if (employees == null || employees.isEmpty()) {
            return 0;
        }
        
        String creator = SecurityUtils.getUsername();
        for (TmsEmployee employee : employees) {
            // 设置创建人和时间
            employee.setCreator(creator);
            employee.setUpdateBy(creator);
            // 如果没有员工ID，系统会自动生成
            employeeMapper.insertEmployee(employee);
        }
        return employees.size();
    }
}